/**
 * futures : masterlink.futures.controller.IndexController.java
 */
package masterlink.futures.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import masterlink.futures.dao.AlertDao;
import masterlink.futures.util.WebUtils;
import masterlink.futures.vo.Alert;
import masterlink.futures.vo.Employee;
import masterlink.futures.vo.Group;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import baytony.util.Util;

/**
 * TODO Write the description
 *
 * @author : tonyyang
 * Create date : 2011/9/30
 * @version 1.0.0	
 */
@Controller
@RequestMapping(value = "/info")
public class AlarmController extends BasicController{
	
	@Autowired
	private AlertDao dao;
	
	@RequestMapping(method=RequestMethod.GET)
	@Override
	public String index(HttpServletRequest req){
		Employee emp=WebUtils.getLogEmployee(req);
		List<Group> all=emp.getAllGroups();
		List<Alert> a=new ArrayList<Alert>();
		if(!Util.isEmptyList(all)){
			for(Group g:all){
				a.addAll(dao.findAlerts(g));
			}
		}
		log.trace("{} alert found for {}",a.size(),emp);
		req.setAttribute("ALERTS", a);
		return "footer/index";
	}
	
	@RequestMapping(value = "/max")
	public void max(HttpSession session){
		session.setAttribute("MODE", "max");	
	}
	
	@RequestMapping(value = "/min")
	public void min(HttpSession session){
		session.removeAttribute("MODE");	
	}
	
}
